package com.amuse.amuse.mapper.facility_permissions;

import com.amuse.amuse.entity.facilities;
import com.amuse.amuse.entity.facilityReservations;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
/*
* 预约模块的权限
* */
public interface FacilityPermissionDao {
    /*
    * 管理员增加场地
    * */
    @Insert( "insert into facilities(facilityTypeId,location,capacity,rate,availablity) values(#{facilityTypeId},#{location},#{capacity},#{rate},#{availablity})")
    public int addFacility( facilities facilities);

    /*
    * 管理员删除场地
    * */
    @Delete("delete from facilities where facilityId = #{facilityId}")
    public int deleteFacility(Integer facilityId);

    /*
    * 管理员修改场地信息
    * */
    @Update("update facilities set facilityTypeId = #{facilityTypeId},location = #{location},capacity = #{capacity},rate = #{rate},availablity = #{availablity} where facilityId = #{facilityId}")
    public int updateFacility(facilities facilities);


    /*
    * 管理员和学生根据typeName查看对应的场地信息
    * */
    @Select("SELECT f.*, ft.typeName FROM facilities f JOIN facilitiesTypes ft ON f.facilityTypeId = ft.typeId WHERE ft.typeName = #{typeName}")
    public List<facilities> findFacilityByTypeName(@Param("typeName") String typeName);

    /*
    * 学生预约场地
    * */
    @Insert("insert into facilityReservations(facilityId,studentId,startTime,endTime,reservationDate,status) values(#{facilityId},#{studentId},#{startTime},#{endTime},#{reservationDate},#{status})")
    public int addFacilityReservations(@Param("facilityId") Integer facilityId, @Param("studentId") Integer studentId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("reservationDate") String reservationDate, @Param("status") String status);

    /*
    * 学生查询自己的预约
    * */

    @Select("select fr.*,f.location,f.rate from facilityReservations fr join facilities f on fr.facilityId  = f.facilityId where studentId=#{studentId}")
    public List<facilityReservations> findFacilityReservations(@Param("studentId") Integer studentId);
    /*
    * 学生取消预约场地
    * */
    @Delete("delete from facilityReservations where studentId = #{studentId} and facilityId = #{facilityId}")
    public int deleteFacilityReservations(@Param("studentId") Integer studentId, @Param("facilityId") Integer facilityId);

    /*
    * 学生修改预约场地
    * */
    @Update("update facilityReservations set startTime = #{startTime},endTime = #{endTime},reservationDate = #{reservationDate} where studentId = #{studentId} and facilityId = #{facilityId}")
    public int updateFacilityReservations(@Param("studentId") Integer studentId, @Param("facilityId") Integer facilityId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("reservationDate") String reservationDate);


    /*
    * 更新场地状态
    * */
    @Update("update facilities set availablity = #{availablity} where facilityId = #{facilityId}")
    public int updateFacilityAvailablity(@Param("facilityId") Integer facilityId, @Param("availablity") String availablity);


}
